package com.gitee.wsl.text.regex.sample


//16进制颜色
val Regex.Companion.COLOR_16: Regex
    get() = """^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3}|[a-fA-F0-9]{8}|[a-fA-F0-9]{4})${'$'}""".toRegex()

// Regex patterns
private const val PATTERN_PART_VALUE = "((?:\\+|\\-)?(?:[0-9]*\\.[0-9]*|[0-9]+)%?)"
private const val PATTERN_PART_PERCENTAGE = "((?:\\+|\\-)?(?:(?:[0-9]*\\.[0-9]*|[0-9]+)%|0))"
private const val PATTERN_PART_OPACITY = "([0-9]*\\.[0-9]*|[0-9]+)"

private const val PREFIX_RGB = "rgb"
private const val PREFIX_RGBA = "rgba"
private const val PREFIX_HSL = "hsl"
private const val PREFIX_HSLA = "hsla"


val Regex.Companion.COLOR_RGB: Regex
    get() = Regex(
        "^$PREFIX_RGB\\s*\\(\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_VALUE\\s*\\)$",
    )

val Regex.Companion.COLOR_RGBA: Regex
    get() = Regex(
        "^$PREFIX_RGBA\\s*\\(\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_OPACITY\\s*\\)$",
    )

val Regex.Companion.COLOR_HSL: Regex
    get() = Regex(
        "^$PREFIX_HSL\\s*\\(\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_PERCENTAGE\\s*,\\s*$PATTERN_PART_PERCENTAGE\\s*\\)$",
    )

val Regex.Companion.COLOR_HSLA: Regex
    get() = Regex(
        "^$PREFIX_HSLA\\s*\\(\\s*$PATTERN_PART_VALUE\\s*,\\s*$PATTERN_PART_PERCENTAGE\\s*,\\s*$PATTERN_PART_PERCENTAGE\\s*,\\s*$PATTERN_PART_OPACITY\\s*\\)$",
    )
